<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>支付</title>
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport"/>
    <meta content="yes" name="apple-mobile-web-app-capable"/>
    <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
    <meta content="telephone=no" name="format-detection"/>
    <js href="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"/>
    <link rel="stylesheet" href="__CSS__/ydui.css"/>
    <script src="__JS__/ydui.flexible.js"></script>

</head>
<body>
<section class="g-flexview" id="view">

</section>
<!-- 引入jQuery 2.0+ -->
<script src="//apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="__JS__/ydui.js"></script>
<script type="text/javascript">
    var dialog = YDUI.dialog;
    jsparam = JSON.parse('{$wxPay}');
    var returnurl = '{$returnurl}';
    callpay();
    //调用微信JS api 支付
    function jsApiCall(obj) {
        WeixinJSBridge.invoke(
                'getBrandWCPayRequest',
                jsparam,
                function (res) {
                    var url = '{$url}';
                    if (res.err_msg == 'get_brand_wcpay_request:ok') {
                        dialog.alert('<span style="color:#00BB00">支付成功！</span>');
                        if(returnurl == ''){
                            history.back();
                        }else{
                            window.location.href = returnurl;
                        }
                    } else {
                        if (typeof res.err_code != 'undefined' && res.err_code == 3 || typeof res.err_code != 'undefined' && res.err_code == 2) {
                        } else {
                            dialog.alert('<span style="color:#BB0000">支付失败</span>');
                        }
                        history.back();
                    }
                    console.log(res);
                }
        );
    }
    function callpay(obj) {
        if (typeof WeixinJSBridge == "undefined") {
            if (document.addEventListener) {
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            } else if (document.attachEvent) {
                document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        } else {
            jsApiCall(obj);
        }
    }


</script>
</body>
</html>